/*****************
START
*****************/

/* 
This do-file provides the code used to produce the empirical findings in the 
following paper, published in PLOS ONE.

"Deliberative panels as a source of public knowledge: 
A large-sample test of the Citizens' Initiative Review"

Authors: John Gastil, Kristinn Már Ársælsson, Katherine R. Knobloch, David L. 
Brinker, Robert C. Richards, Jr., Justin Reedy, and Stephanie Burkhalter.
*/



/*****************
SETUP AND DATA
*****************/

* Install modules if needed

/*
ssc install revrs
ssc install mat2txt
ssc install asdoc
*/


use cir_voter_knowledge_plosone.dta



/*****************
GENERATE VARIABLES
*****************/

* Factual Accuracy

revrs TrueFalseAnswer
recode revTrueFalseAnswer (1 = -2) (2 = -1) (3 = 0)
recode revTrueFalseAnswer (4 = 1) (5 = 2)

gen FactualAccuracy = .
replace FactualAccuracy = TrueFalseAnswer if ClaimTruth == "TRUE"
replace FactualAccuracy = revTrueFalseAnswer if ClaimTruth == "FALSE"
replace FactualAccuracy = TrueFalseAnswer if ClaimTruth == "Likely"
replace FactualAccuracy = revTrueFalseAnswer if ClaimTruth == "Unlikely"


* Party ID2

gen PID_2 = .
replace PID_2 = 0 if PartyID7 < 4
replace PID_2 = 1 if PartyID7 > 4 & PartyID7 ~= .



* Treatment Variables

gen Guide_vs_CIR = .
replace Guide_vs_CIR = 0 if ConditionOfficial == 1 & ConditionCIR == 0
replace Guide_vs_CIR = 1 if ConditionOfficial == 0 & ConditionCIR == 1

gen Guide_vs_CIRGuide = .
replace Guide_vs_CIRGuide = 0 if ConditionOfficial == 1 & ConditionCIR == 0
replace Guide_vs_CIRGuide = 1 if ConditionOfficial == 1 & ConditionCIR == 1

gen Nothing_vs_CIR = .
replace Nothing_vs_CIR = 0 if ConditionOfficial == 0 & ConditionCIR == 0
replace Nothing_vs_CIR = 1 if ConditionOfficial == 0 & ConditionCIR == 1



* DelibFaith Scale (alpha=.66)

alpha DelibFaith_Sit DelibFaith_Disc DelibFaith_Civ, gen(DelibFaith_Scale)



* Knowledge Claims with sufficient statistical power for detecting main effects.

global idclaims_full 1 5 45 46 47 48 49 50 51 52 53 54 67 68 69 70 72 73 ///
74 75 76 77 79 81 82 83 84 85 86 89 90 91 92 93 94 95 96 100 101 102 ///
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 ///
122 123 124 125 126 127 128 129 130 131 

/* 
Knowledge Claims with sufficient statistical power to detect effect heterogeneity.
*/

global idclaims_no 101 100 99 97 96 95 94 77 76 75 74 73 72 71 70 69 68 67



* Generating Data for Meta-Analysis

capture postutil clear
postfile handle str3 variable float (n1 mean1 sd1 n2 mean2 sd2) using ttest_results_issues, replace

local names Casinos GMOLabelsCO GMOLabelsOR GMOSeeds GrossReceipts HousingCA HousingPDX Kicker MarijuanaAZ MarijuanaMA Nursing Sentencing TopTwoPrimary

	foreach x of local names {
	
	di "`x'"
	ttest FactualAccuracy if ID_Issue == "`x'", by(ConditionCIR) welch
	post handle ("`x'")  (`r(N_2)')  (`r(mu_2)')  (`r(sd_2)')  (`r(N_1)')  (`r(mu_1)')  (`r(sd_1)')
		
	}

postclose handle



/*****************
TABLES AND FIGURES
*****************/

/*
Analysis is presented in the order they appear in the publication. Meta analysis
is handled in a separate do-file.
*/

cls


* Table S2 and S4: Multilevel Main Effect

meologit FactualAccuracy i.ConditionCIR ///
|| ID_Claim: || ID_Issue:, vce(robust) or
margins ConditionCIR



* Table S3 and Figure S1: Pooled Main Effects

ttest FactualAccuracy, by(ConditionCIR) welch
esize twosample FactualAccuracy, by(ConditionCIR) welch
tab FactualAccuracy ConditionCIR, row col



* See separate do-file for meta-analysis (e.g. Figure 2)



*  T-tests for individual knowledge claims (Log File)

cls

log using claims_ttests, replace

	foreach n of global idclaims_full {

	disp "`n'"
	disp "Effect of Reading CIR"
	capture noisily ttest FactualAccuracy if ID_Claim == `n', by(ConditionCIR)
	gen t`n' = (r(mu_1) - r(mu_2)) / r(sd)
	gen p`n' = r(p)
 	
	}

log close



* Table S6 and Figure S3

cls

meologit FactualAccuracy i.Guide_vs_CIR if ///
(ID_Issue == "Casinos" | ID_Issue == "HousingCA" | ID_Issue == "HousingPDX" ///
| ID_Issue == "Kicker" | ID_Issue == "Nursing" | ID_Issue == "Sentencing") ///
|| ID_Claim: || ID_Issue:, vce(robust) or
margins Guide_vs_CIR



* Table S7 and Figure 3

meologit FactualAccuracy i.Guide_vs_CIRGuide if ///
(ID_Issue == "GrossReceipts" | ID_Issue == "HousingPDX" | ///
ID_Issue == "MarijuanaAZ" | ID_Issue == "MarijuanaMA" | ID_Issue == "Nursing") ///
|| ID_Claim: || ID_Issue:, vce(robust) or
margins Guide_vs_CIRGuide



* Table S8

meologit FactualAccuracy i.Nothing_vs_CIR if ///
(ID_Issue == "Casinos" | ID_Issue == "GMOSeeds" | ID_Issue == "HousingPDX" ///
| ID_Issue == "Kicker" | ID_Issue == "Nursing" | ID_Issue == "Sentencing") ///
|| ID_Claim: || ID_Issue:, vce(robust) or



* Table S9

ttest FactualAccuracy if Nothing_vs_CIR == 0, by(PID_2) welch

disp (r(mu_1) -  r(mu_2)) / r(sd_1)
 

 
* Table S10 and alternative treatment regimes mentioned in footnote 4.

meologit FactualAccuracy i.Nothing_vs_CIR##i.PID_2 ///
|| ID_Claim: || ID_Issue:, vce(robust) or
margins PID_2

meologit FactualAccuracy i.Guide_vs_CIR##i.PID_2  ///
|| ID_Claim: || ID_Issue:, vce(robust) or

meologit FactualAccuracy i.Guide_vs_CIRGuide##i.PID_2 ///
|| ID_Claim: || ID_Issue:, vce(robust) or



/*
Accuracy vs directional motivated reasoning using all 18 knowledge claims and 
treatment regimes (Log File).
*/

cls

log using claims_partybias, replace

*Main Effects & by Democrats/Republicans for each Issue
	foreach n of global idclaims_no {

	disp "Factual Accuracy Difference"
	capture noisily ttest FactualAccuracy if ///
	ID_Claim == `n' & Nothing_vs_CIR == 0, by(PID_2)
	
	disp "Democrats"
	capture noisily ttest FactualAccuracy if ///
	ID_Claim == `n' & PID_3 == 1, by(Nothing_vs_CIR) welch
	
	disp "Republicans"
	capture noisily ttest FactualAccuracy if ///
	ID_Claim == `n' & PID_3 == 3, by(Nothing_vs_CIR) welch
	
	disp "Interaction Test"
	capture noisily ologit FactualAccuracy i.Nothing_vs_CIR##i.PID_2 if ///
	ID_Claim == `n', vce(robust)

	}

log close



* Table S11
  
meologit FactualAccuracy i.ConditionCIR##c.DelibFaith_Scale /// 
|| ID_Claim: || ID_Issue:, vce(robust) or



/**********
POWER ANALYSIS
**********/

ttest FactualAccuracy if ID_Claim == 74 & PID_2 == 0, by(Nothing_vs_CIR)

ttest FactualAccuracy if ID_Claim == 74 & PID_2 == 1, by(Nothing_vs_CIR)

anova FactualAccuracy Nothing_vs_CIR##PID_2 if ID_Claim == 74

power twoway  -.160793 -.2777778 \ -.7262181 -.4727273, ///
varerror(1.1592727) cellweights(2 1 \ 2 1)

power twoway  -.160793 -.2777778 \ -.7262181 -.4727273, ///
varerror(1.1592727) cellweights(2 1 \ 2 1) n(881)

power twoway, varerror(1.1592727) varrowcol(.05) ///
cellweights(2 1 \ 2 1) nrows(2) ncols(2)
 
power twoway, varerror(1.1592727) varrowcol(.014) ///
cellweights(2 1 \ 2 1) nrows(2) ncols(2) power(.9) 




/*****************
END
*****************/